package com.xiweicheng.test.springboot.im.admin.entity.security;

import static javax.persistence.GenerationType.IDENTITY;

import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import lombok.Data;
import lombok.EqualsAndHashCode;

@Entity
@Table(name = "groups")
@Data
@EqualsAndHashCode(of = { "groupName" })
public class Group implements Serializable {

    private static final long serialVersionUID = -3020819369767496881L;

    @Id
    @GeneratedValue(strategy = IDENTITY)
    @Column(name = "id", unique = true, nullable = false)
    private Long id;

    @Column(name = "group_name", unique = true, nullable = false, length = 50)
    private String groupName;

    @OneToMany(fetch = FetchType.EAGER, mappedBy = "group")
    private Set<GroupMember> groupMembers = new HashSet<>();

    @OneToMany(fetch = FetchType.EAGER, mappedBy = "group")
    private Set<GroupAuthority> groupAuthorities = new HashSet<>();

    public Group() {

    }

    public Group(String groupName) {

        this.groupName = groupName;
    }

    public Group(String groupName, Set<GroupMember> groupMembers, Set<GroupAuthority> groupAuthorities) {

        this.groupName = groupName;
        this.groupMembers = groupMembers;
        this.groupAuthorities = groupAuthorities;
    }

}
